package com.yitao.cms.controller.hotSearch;

import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedInput;
import com.skipper.base.bean.PagedOutput;
import com.yitao.client.dto.shopInfo.HotSearchDto;
import com.yitao.cms.config.aopLog.LogAnnotation;
import com.yitao.cms.service.hotSearch.HotSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(value = "/cms/hotSearch", description = "热门搜索相关接口", tags = {"cms-hotSearch"})
@RestController
@RequestMapping(value = "/hotSearch", produces = {"application/json"})
public class HotSearchController {
    @Autowired
    private HotSearchService hotSearchService;

    @ApiOperation("热搜编辑/添加")
    @LogAnnotation(targetType = "hotSearch-updateHotSearch", remark = "热搜编辑/添加")
    @RequestMapping(value = "/updateHotSearch", method = RequestMethod.POST)
    public DataOutput updateHotSearch(@RequestBody HotSearchDto hotSearchDto, HttpServletRequest request) {
        return hotSearchService.updateHotSearch(hotSearchDto, request);
    }

    @ApiOperation("查询热搜列表")
    @RequestMapping(value = "/hotSearchList", method = RequestMethod.POST)
    public PagedOutput<HotSearchDto> findUserList(
            HttpServletRequest request,
            @ApiParam(value = "热搜词") @RequestParam(value = "searchKey", required = false) String searchKey,
            @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
            @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize) {

        PagedInput pagedInput = new PagedInput(pageSize,pageNo);
        return hotSearchService.hotSearchList(request,searchKey,pagedInput);
    }

    @ApiOperation("删除热搜")
    @LogAnnotation(targetType = "hotSearch-deleteHotSearch", remark = "删除热搜")
    @RequestMapping(value = "/deleteHotSearch", method = RequestMethod.POST)
    public DataOutput deleteHotSearch(  @ApiParam(value = "id") @RequestParam(value = "id") Long id,
             HttpServletRequest request) {
        return hotSearchService.deleteHotSearch(id, request);
    }


}
